<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/11/24
 * Time: 9:05
 */
namespace app\web\controller;

use app\web\util\AlibabaUtil;

class CallBack{
    /**
     * @todo PDD回调处理
     * @author ZJF
     */
    public function index(){
        $code = request()->param('code/s','');//授权code
        if(!empty($code)){
            //跳转到前端入口页面
            return redirect("http://duohuotong.xingyebao.com/#/?code={$code}");
        }
    }

    /**
     * @todo 代理请求
     * @author ZJF
     */
    public function proxyRequest(){
        if(request()->isPost()){
            $name = request()->param('name/s','');
            $param = request()->param('param/a',[]);//需要打标签的数据
            $shop_id = request()->param('shop_id',1);
            $method = request()->param('method/s','POST');
            //入参判断
            if(empty($name)){
                return json_ok([],1,'无效的接口');
            }
            if(empty($param) || !is_array($param)){
                return json_ok([],1,'无效的数据');
            }
//            print_data($name,$param,$shop_id,$method);
            //获取打完标签的数据
            $alibaba = new AlibabaUtil();
            $request_data = $alibaba->pub_api($name,$param,$shop_id,$method);
//            print_data($request_data);
            if(isset($request_data['code']) && $request_data['code']!=0){
                return json_ok([],1,'获取失败');
            }
            //成功返回签名后的数据
            return json_ok($request_data['data']);
        }
    }
}